const e = require("express");
const express = require("express");
let app = express();
let _port = 10001;

app.get("/download/:file", function (req, res) {
	let _path = "/root/scpFile/" + req.params.file;
	try {
		res.download(_path, "0621_" + req.params.file, (err) => {
			if (err) {
				console.log(err);
				res.send(err);
			}
		});
	} catch (err_) {
		console.error(err_);
	}
});

app.get("*", function (req, res) {
	res.send("基于express的个人网盘 功能简单，效果拔群");
});

var server = app.listen(_port, function () {
	var host = server.address().address;
	var port = server.address().port;
	console.log(server.address());
	console.log("app    应用实例，访问地址为 http://%s:%s", host, port);
	console.log("\n");
});
server.close();
server.listen(_port, "0.0.0.0", () => {
	var host = server.address().address;
	var port = server.address().port;
	console.log(server.address());
	console.log("Server 应用实例，访问地址为 http://%s:%s", host, port);
	console.log("\n");
});
